package com.gpframework.common.utils;

import cn.hutool.core.lang.ObjectId;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * id生成工具栏
 *
 * @author zcl
 */
@Slf4j
public class IdGenUtils {

    /**
     * 参数1为终端ID
     * 参数2为数据中心ID
     */
    private static final Snowflake snowflake = IdUtil.getSnowflake(1, 1);

    /**
     * 获取雪花算法id
     *
     * @return
     */
    public static Long getSnowId() {
        return snowflake.nextId();
    }

    /**
     * 获取雪花算法id字符串
     *
     * @return
     */
    public static String getSnowIdStr() {
        return snowflake.nextIdStr();
    }

    /**
     * 获取字符串id类似UUID
     *
     * @return
     */
    public static String getStrId() {
        return ObjectId.next();
    }


    public static void main(String[] args) {
        log.info(getStrId());
    }
}
